
function generateRandomPassword(length = 12, includeSpecialChars = true): string {
    if (typeof window !== "undefined" && window.crypto && window.crypto.getRandomValues) {
        const possibleChars =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()"

        let password = ""
        const buf = new Uint8Array(length)
        window.crypto.getRandomValues(buf)

        for (let i = 0; i < length; i++) {
            password += possibleChars.charAt(buf[i] % possibleChars.length)
        }

        return password
    } else {
        throw new Error("Crypto API not supported in this environment")
    }
}

export { generateRandomPassword };